package carnet;

import java.util.ArrayList;
import exceptions.*;

public class Contact {
	private Champ nom;
	private Champ prenom;
	private Champ adresse;
	private Champ telephone;
	private ArrayList<Champ> autresChamps;
	
	public Contact(String n, String p, String a, String t) throws Exception{
		nom = new Champ("nom", n, Champ.Type.Default);
		prenom = new Champ("prenom", p,Champ.Type.Default);
		adresse = new Champ("adresse", a, Champ.Type.Default);
		Champ tel = new Champ("telephone", t, Champ.Type.Telephone);
		if(tel.isTelephone())
			telephone = tel;
		else
			throw new NotTelephoneException();
		autresChamps = new ArrayList<Champ>();
	}
	
	public void addChamp(Champ c){
		autresChamps.add(c);
	}
	
	public void addChamp(String n, String v, Champ.Type t) throws Exception{
		Champ c = new Champ(n,v,t);
		autresChamps.add(c);
	}
	
	public void removeChamp(Champ c){
		autresChamps.remove(c);
	}

	// -------------------------------------
	// Getters / Setters
	public Champ getNom() {
		return nom;
	}

	public void setNom(Champ nom) {
		this.nom = nom;
	}

	public Champ getPrenom() {
		return prenom;
	}

	public void setPrenom(Champ prenom) {
		this.prenom = prenom;
	}

	public Champ getAdresse() {
		return adresse;
	}

	public void setAdresse(Champ adresse) {
		this.adresse = adresse;
	}

	public Champ getTelephone() {
		return telephone;
	}

	public void setTelephone(Champ telephone) {
		this.telephone = telephone;
	}

	public ArrayList<Champ> getAutresChamps() {
		return autresChamps;
	}
	
	public Champ getAutreChamp(String nomchamp){
		for(Champ c : autresChamps){
			if(c.getNom().equals(nomchamp))
				return c;
		}
		return null;
	}
	
	// Visitor
	public void accept(Visitor v){
		v.visitContact(this);	
	}
}
